package com.jiamao.goplay.ui.user.vm;

import android.app.Application;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableBoolean;
import androidx.databinding.ObservableField;
import androidx.databinding.ObservableInt;

import com.jiamao.goplay.BR;
import com.jiamao.goplay.R;
import com.jiamao.goplay.data.DataRepository;
import com.jiamao.goplay.ui.settings.SettingsFragment;
import com.tamsiree.rxkit.view.RxToast;

import androidx.databinding.ObservableList;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.MultiItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.binding.command.BindingConsumer;
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent;
import me.tatarka.bindingcollectionadapter2.ItemBinding;
import me.tatarka.bindingcollectionadapter2.OnItemBind;

public class UpdateAHVM extends BaseViewModel<DataRepository> {
    //用户名的绑定
    public ObservableField<String> len = new ObservableField<>("0/3");


    //封装一个界面发生改变的观察者
    public UpdateAHVM.UIChangeObservable uc = new UpdateAHVM.UIChangeObservable();

    public class UIChangeObservable {
        //密码开关观察者
        public SingleLiveEvent<Boolean> pSwitchEvent = new SingleLiveEvent<>();
    }

    public UpdateAHVM(@NonNull Application application, DataRepository repository) {
        super(application, repository);

        observableList.add(new UserUpdateAHItemVM(this,"运动"));
        observableList.add(new UserUpdateAHItemVM(this,"音乐"));
        observableList.add(new UserUpdateAHItemVM(this,"茶"));
        observableList.add(new UserUpdateAHItemVM(this,"阅读"));
        observableList.add(new UserUpdateAHItemVM(this,"购物"));
        observableList.add(new UserUpdateAHItemVM(this,"酒"));

        observableList.add(new UserUpdateAHItemVM(this,"喝一杯"));
        observableList.add(new UserUpdateAHItemVM(this,"棋牌游戏"));
        observableList.add(new UserUpdateAHItemVM(this,"足球"));
        observableList.add(new UserUpdateAHItemVM(this,"瑜伽"));
        observableList.add(new UserUpdateAHItemVM(this,"咖啡"));

        observableList.add(new UserUpdateAHItemVM(this,"美食"));
        observableList.add(new UserUpdateAHItemVM(this,"电影"));
        observableList.add(new UserUpdateAHItemVM(this,"蹦迪"));
        observableList.add(new UserUpdateAHItemVM(this,"唱歌"));
        observableList.add(new UserUpdateAHItemVM(this,"游泳"));

        observableList.add(new UserUpdateAHItemVM(this,"早午餐"));
        observableList.add(new UserUpdateAHItemVM(this,"跳舞"));
        observableList.add(new UserUpdateAHItemVM(this,"野餐"));
        observableList.add(new UserUpdateAHItemVM(this,"冲浪"));
        observableList.add(new UserUpdateAHItemVM(this,"拍视频"));

        observableList.add(new UserUpdateAHItemVM(this,"潜水"));
        observableList.add(new UserUpdateAHItemVM(this,"烹饪"));
        observableList.add(new UserUpdateAHItemVM(this,"旅行"));
        observableList.add(new UserUpdateAHItemVM(this,"自驾游"));
        observableList.add(new UserUpdateAHItemVM(this,"精酿啤酒"));

        observableList.add(new UserUpdateAHItemVM(this,"摄影"));
        observableList.add(new UserUpdateAHItemVM(this,"聊天"));
        observableList.add(new UserUpdateAHItemVM(this,"活动聚会"));
         observableList.add(new UserUpdateAHItemVM(this,"手办"));
         observableList.add(new UserUpdateAHItemVM(this,"艺术"));

         observableList.add(new UserUpdateAHItemVM(this,"收藏"));
        observableList.add(new UserUpdateAHItemVM(this,"奢侈品"));
        observableList.add(new UserUpdateAHItemVM(this,"汽车"));
        observableList.add(new UserUpdateAHItemVM(this,"手表"));
        observableList.add(new UserUpdateAHItemVM(this,"读书"));

        observableList.add(new UserUpdateAHItemVM(this,"占星术"));
        observableList.add(new UserUpdateAHItemVM(this,"高尔夫"));
        observableList.add(new UserUpdateAHItemVM(this,"动漫"));
        observableList.add(new UserUpdateAHItemVM(this,"猫咪"));
        observableList.add(new UserUpdateAHItemVM(this,"登山"));

        observableList.add(new UserUpdateAHItemVM(this,"萌宠"));
        observableList.add(new UserUpdateAHItemVM(this,"钓鱼"));
        observableList.add(new UserUpdateAHItemVM(this,"健身"));
        observableList.add(new UserUpdateAHItemVM(this,"骑行"));
        observableList.add(new UserUpdateAHItemVM(this,"王者荣耀"));


        observableList.add(new UserUpdateAHItemVM(this,"吃鸡"));
        observableList.add(new UserUpdateAHItemVM(this,"网络游戏"));
        observableList.add(new UserUpdateAHItemVM(this,"园艺"));
        observableList.add(new UserUpdateAHItemVM(this,"狗狗"));
        observableList.add(new UserUpdateAHItemVM(this,"二次元"));

        observableList.add(new UserUpdateAHItemVM(this,"驴友"));

    }    //登录按钮的点击事件
    public BindingCommand backOnClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            finish();
        }
    });


    //给RecyclerView添加ObservableList
    public ObservableList<MultiItemViewModel> observableList = new ObservableArrayList<>();


    public ObservableList<MultiItemViewModel> observableListSelect = new ObservableArrayList<>();
    //RecyclerView多布局添加ItemBinding
    public ItemBinding<MultiItemViewModel> itemBinding = ItemBinding.of(new OnItemBind<MultiItemViewModel>() {
        @Override
        public void onItemBind(ItemBinding itemBinding, int position, MultiItemViewModel item) {
            //通过item的类型, 动态设置Item加载的布局
            String itemType = (String) item.getItemType();
            itemBinding.set(BR.viewModel, R.layout.user_update_ah_item_layout);
            // itemBinding.set(BR.viewModel, R.layout.msg_home_item_layout);

        }
    });

    public int num;

    public void updateUI(UserUpdateAHItemVM vm){
        if (vm.isSelect.get()){
            observableListSelect.add(vm);
            num++;
        }else {
            observableListSelect.remove(vm);
            num--;

        }
        len.set(num+"/3");

        if (num>=3){
            uc.pSwitchEvent.setValue(true);
        }
        else {
            uc.pSwitchEvent.setValue(false);
        }

    }



    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
